package tech.pdai.springframework.interceptor;


import lombok.extern.slf4j.Slf4j;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 拦截器
 */
@Slf4j
public class RoleMethodInterceptor implements MethodInterceptor {
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        if(method.getName().equalsIgnoreCase("getName")){
            log.info("调用 getName 方法 ");
        }
        else if(method.getName().equalsIgnoreCase("setName")){
            objects = new Object[]{"被替换掉啦"};
        }
        return methodProxy.invokeSuper(o, objects);
    }
}
